function onCommonRemotingResultInit(param, data, slot)
{
	var containerName_tf=Packages.system.mlf.GateKeeper.scanElement(slot, "containerName");
	var containerName=containerName_tf.text;
	Packages.system.render.Transition.irisType1(Packages.system.mlf.GateKeeper.scanElement(slot, containerName));
	
	var evtTargetArr:Array=new Array();
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "resultReturnSpot"));
	Packages.system.events.StateFulButtonEvent.initialize(evtTargetArr);

	var resultBody_tf=Packages.system.mlf.GateKeeper.scanElement(slot, "resultBody");
	var returnMessage_tf=Packages.system.mlf.GateKeeper.scanElement(slot, "errorMessage");
	var returnCode_tf=Packages.system.mlf.GateKeeper.scanElement(slot, "returnCode");

	var result:String="RST_fail";
	if (returnCode_tf.text=="0") result="RST_success";
	var resultBody_str=Packages.system.mlf.GateKeeper.scanDictionary(resultBody_tf, resultBody_tf.text);
	resultBody_str+=Packages.system.mlf.GateKeeper.accessSystemConfig(result)+" ";
	
	if (result=="RST_fail") resultBody_str+=returnMessage_tf.text;
	var resultBody_final=Packages.system.utils.TextUtil.formatText("tfContentCenter", resultBody_str);
	resultBody_tf.htmlText=resultBody_final;

	Packages.modula.MessageCenter.send(resultBody_str, 1, 0);
	
	var initCall_tf=Packages.system.mlf.GateKeeper.scanElement(slot, "initCall");
	if (initCall_tf!=null)
	{
		Packages.system.mlf.GateKeeper.dispatchMessage({type:initCall_tf.text, param:returnCode_tf.text});
	}
}

var dataResult:Object;
var selectedDataId:String;

// var dataType:String;		// books / objects
var detailTemplate:String;	// BookDetail / MemberDetail
var scenePath:String;		// content/bookPage/BookSpecial

function popupSelectedDataDetail(rst:Object, id:String, detail:String, scene:String)
{
	dataResult=rst;
	selectedDataId=id;
	// dataType=type;
	detailTemplate=detail;
	scenePath=scene;
	Packages.system.mlf.GateKeeper.loadML2byPath("app/popup/"+detailTemplate+".xml");
}

function onBookDetailInit(param, data, slot)
{
	// Render.init
	Packages.system.render.Transition.irisType1(Packages.system.mlf.GateKeeper.scanElement(slot, "basic"));
	// Event.init
	var evtTargetArr:Array=new Array();
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "linkSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "closeSpot"));
	Packages.system.events.StateFulButtonEvent.initialize(evtTargetArr);
	// prefetch bookItem
	var bookItem;
	for (var i=0; i<dataResult.books.length; i++)
	{
		bookItem=dataResult.books[i];
		if (bookItem.bookId==selectedDataId)
		{
			break;
		}
	}
	// cover image
	var clipCover=Packages.system.mlf.GateKeeper.scanElement(slot, "clipCover");
	var mclListener=new Object();
	mclListener.owner=this;
	mclListener.onLoadInit=function(target_mc:MovieClip)
	{
		this.owner.resize(target_mc);
	}
	if (bookItem.image!=null)
	{
		mlf.mcmanager.dynamicloading.LoadApp.loadAppLoader(bookItem.image, clipCover, "cover", mclListener);
	}
	// data info
	var args:Array=new Array();
	args.push(bookItem);
	var vo:MovieClip=Packages.model.vo.BookView;
	var voData=vo["popup"].apply(vo, args);
	Packages.system.mlf.GateKeeper.setValue(voData.content, slot);

	Packages.system.mlf.GateKeeper.addListener("onReleaseButtonEvent", this);
}

function onMemberDetailInit(param, data, slot)
{
	// Render.init
	Packages.system.render.Transition.irisType1(Packages.system.mlf.GateKeeper.scanElement(slot, "basic"));
	// Event.init
	var evtTargetArr:Array=new Array();
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "linkSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "closeSpot"));
	evtTargetArr.push(Packages.system.mlf.GateKeeper.scanElement(slot, "friendSpot"));
	Packages.system.events.StateFulButtonEvent.initialize(evtTargetArr);
	// prefetch memberItem
	var memberItem;
	var dataCollection=dataResult.objects?dataResult.objects:dataResult.members;
	for (var i=0; i<dataCollection.length; i++)
	{
		memberItem=dataCollection[i];
		if (memberItem.memberId==selectedDataId)
		{
			break;
		}
	}
	// cover image
	var clipCover=Packages.system.mlf.GateKeeper.scanElement(slot, "clipCover");
	var mclListener=new Object();
	mclListener.owner=this;
	mclListener.onLoadInit=function(target_mc:MovieClip)
	{
		this.owner.resize(target_mc);
	}
	if (memberItem.image!=null)
	{
		mlf.mcmanager.dynamicloading.LoadApp.loadAppLoader(memberItem.image, clipCover, "cover", mclListener);
	}
	// data info
	var args:Array=new Array();
	args.push(memberItem);
	var vo:MovieClip=Packages.model.vo.UserView;
	var voData=vo["popup"].apply(vo, args);
	Packages.system.mlf.GateKeeper.setValue(voData.content, slot);

	Packages.system.mlf.GateKeeper.addListener("onReleaseButtonEvent", this);
}

function onReleaseButtonEvent(evt:Object)
{
	if (evt.param=="closeSpot")
	{
		// Packages.system.mlf.GateKeeper.unloadML2bySlot("BookDetail");
		Packages.system.mlf.GateKeeper.removeListener("onReleaseButtonEvent", this);
		Packages.system.mlf.GateKeeper.removePopup(detailTemplate);
	}
	else if (evt.param=="linkSpot")
	{
		Packages.system.mlf.GateKeeper.removeListener("onReleaseButtonEvent", this);
		Packages.system.mlf.GateKeeper.removePopup(detailTemplate);
		Packages.components.SceneAgent.loadScene(scenePath+"?id="+selectedDataId);
	}
	else if (evt.param=="friendSpot")
	{
		//TODO: send the adding friend request
	}
}

function resize(target:MovieClip)
{
	zoom=Packages.system.utils.ImageUtil.minSize(target, 120, 150);
	target._xscale=zoom;
	target._yscale=zoom;
	// centralize the target
	var offsetX:Number=(target._width-120)/2;
	target._x=-offsetX;
	var offsetY:Number=(target._height-150)/2;
	target._y=-offsetY;
}
